package com.lx;

import com.domain.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/param")
public class Param {
    /**
     * 请求参数绑定
     * @return
     */
    @RequestMapping("/test")
    public String testparam(String username){
        System.out.println("参数绑定");
        System.out.println(username);
        return "success";
    }

    /**
     *请求参数绑定封装到JavaBean的类中
     * @return
     */
    @RequestMapping("/save")
    public String save(Account account){
        System.out.println("请求参数绑定封装到JavaBean的类中");
        System.out.println(account.toString());
        return "success";
    }

    /**
     *Servlet原生API
     * @return
     */
    @RequestMapping("/testServlet")
    public String testServlet(HttpServletRequest request, HttpServletResponse response){
        System.out.println("Servlet原生API");
        HttpSession session = request.getSession();
        System.out.println(session);
        ServletContext context = session.getServletContext();
        System.out.println(context);
        String path = request.getContextPath();
        System.out.println(path);
        return "success";
    }
}
